package com.etocrm.saas.lib.base.log.requestlog.register;

import com.etocrm.saas.lib.base.log.requestlog.interceptor.HttpLogInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 注册拦截器
 * Created by Xs on 2022/12/14.
 */
@Configuration
public class RequestLogInterceptorRegister implements WebMvcConfigurer {

    @Bean
    public HandlerInterceptor requestLogInterceptor() {
        return new HttpLogInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(requestLogInterceptor())
                .order(Ordered.HIGHEST_PRECEDENCE)
                .excludePathPatterns("/favicon.ico", "/swagger-ui.html", "/v2/api-docs", "/swagger-resources/**", "/webjars/**")
                .addPathPatterns("/**");
    }
}
